package qmlt.evaluating;

import qmlt.dataset.DataSet;
import qmlt.dataset.Instance;
import qmlt.learning.Learner;

@SuppressWarnings("unchecked")
public class ClassificationAccuracyEvaluator<LearnerClass extends Learner>
implements Evaluator<LearnerClass>
{

    @Override
    public float evaluate(LearnerClass learner, DataSet testSet)
    {
        int n = testSet.getInstances().size();
        int hit = 0;
        for (Instance inst : testSet.getInstances())
        {
            Object p = learner.predict(inst);
            if (p.equals(inst.getTarget()))
                hit++;
        }
        return (float) hit / n;
    }

}
